package com.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dao.HeadImageDAO;
import com.dao.UploadImageDAO;
import com.model.HeadImage;
import com.model.UploadImage;
import com.service.ImageStoreService;

@Service
public class ImageStoreServiceImpl implements ImageStoreService{

	@Autowired
	private HeadImageDAO headImageDAO;
	
	@Autowired
	private UploadImageDAO uploadImageDAO;
	
	@Transactional
	public int saveHeadImage(HeadImage image) {
		HeadImage img = this.readHeadImage(image.getPath());
		if(img!=null){
			this.deleteHeadImage(image.getPath());
		}
		return headImageDAO.write(image);
	}

	@Transactional
	public int saveUploadImage(UploadImage image) {

		return uploadImageDAO.write(image);
	}

	@Transactional
	public HeadImage readHeadImage(String path) {

		return headImageDAO.read(path);
	}

	@Transactional
	public UploadImage readUploadImage(String path) {

		return uploadImageDAO.read(path);
	}
	@Transactional
	public int deleteHeadImage(String path) {
		// TODO Auto-generated method stub
		return headImageDAO.delete(path);
	} 

}
